//
//  ProductDetailModel.m
//  sensen_ios
//
//  Created by pro on 16/2/24.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ProductDetailModel.h"

@implementation ProductDetailModel

- (void)setAttributes:(NSDictionary *)jsonDic {
    [super setAttributes:jsonDic];
    
    _p_id = jsonDic[@"id"];
    _introduction = jsonDic[@"name"];
    _sales = jsonDic[@"total_sales"];

    // 规格列表（该商品有哪些规格）
    NSMutableArray *mutableAry = [[NSMutableArray alloc] init];
    if ([_has_sku integerValue]) { // 有多规格
        for (NSDictionary *skuDic in jsonDic[@"sku_list"]) {
            SkuModel *model = [[SkuModel alloc] initContentWithDic:skuDic];
            [mutableAry addObject:model];
        }
        _skuAry = [mutableAry copy];
    } else { // 单规格
        SkuModel *model = [[SkuModel alloc] initContentWithDic:jsonDic[@"sku_info"]];
        [mutableAry addObject:model];
        _skuAry = [mutableAry copy];
    }
    
    
    // 规格列表（该商品有哪些规格）
    [mutableAry removeAllObjects];
    for (NSDictionary *skuIdDic in jsonDic[@"sku_id"]) {
        SkuIdModel *model = [[SkuIdModel alloc] initWithDic:skuIdDic];
        [mutableAry addObject:model];
    }
    _skuIdAry = [mutableAry copy];
    
    // 规格列表（该商品有哪些规格）
    [mutableAry removeAllObjects];
    for (NSDictionary *skuNameDic in jsonDic[@"sku_name"]) {
        SkuNameModel *model = [[SkuNameModel alloc] initWithDic:skuNameDic];
        [mutableAry addObject:model];
    }
    _skuNameAry = [mutableAry copy];

    
    
}

@end
